package org.darkforest.admin.controller;

import org.darkforest.common.services.BundlingService;
import org.darkforest.model.PBundling;
import org.darkforest.vo.AjaxReturnData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Administrator on 2016/1/26.
 */
@Controller
@RequestMapping(value = "operation")
public class BundlingController {

    @Autowired
    private BundlingService bundlingService;


    @RequestMapping(value = "bundlingList")
    public ModelAndView bundlingList(@RequestParam(required = false, defaultValue = "1") int start,
                                     String blName,
                                     String storeName,
                                     @RequestParam(required = false, defaultValue = "") Integer state){
        ModelAndView res = new ModelAndView("operation/bundling/bundling_list");
        PBundling pBundling = new PBundling();
        pBundling.setStart(start);
        pBundling.setBlName("".equals(blName) ? null : blName);
        pBundling.setStoreName("".equals(storeName)?null:storeName);
        pBundling.setBlState("".equals(state)?null:state );
        pBundling.setResultList(bundlingService.findPBundlingListWithGoodsByCondition(pBundling));
        res.addObject("page",pBundling);
        return  res;
    }




    /**
     * 删除优惠套装
     * @param ids
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "delBundlingBatch")
    public @ResponseBody
    AjaxReturnData delBundlingBatch(Integer[] ids) throws Exception {
        String url = "operation/bundlingList";
        AjaxReturnData ajaxReturnData = bundlingService.delBundlingBatch(ids, url);
        return ajaxReturnData;
    }

    /**
     * 修改优惠套餐活动状态
     * @param blId
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "updateBlState")
    public @ResponseBody AjaxReturnData updateBlState(Integer blId,Integer state ) throws Exception {
        String url = "operation/bundlingList";
        AjaxReturnData ajaxReturnData = bundlingService.updateBlState(blId, state, url);
        return ajaxReturnData;
    }

}
